@extends('admin.layouts.base')

@section('title','后台管理系统')

@section('pageHeader','后台管理系统')

@section('pageDesc','DashBoard')

@section('content')

    <div class="row page-title-row" id="dangqian" style="margin:5px;">
        <div class="col-md-6">
            @if($cid==0)
                <span style="margin:3px;" id="cid" attr="{{$cid}}" class="btn-flat text-info"> 顶级菜单</span>
               @else
                <span style="margin:3px;" id="cid"  attr="{{$cid}}" class="text-info"> {{$data->display_name}}
                </span>
            <a style="margin:3px;"  href="/admin/permission"
                    class="btn btn-warning btn-md animation-shake reloadBtn"><i class="fa fa-mail-reply-all"></i> 返回顶级菜单
            </a>
            @endif
        </div>

        <div class="col-md-6 text-right">
            <a href="/admin/permission/{{$cid}}/create" class="btn btn-success btn-md"><i class="fa fa-plus-circle"></i> 添加权限 </a>
        </div>
    </div>
    <div class="row page-title-row" style="margin:5px;">
        <div class="col-md-6">
        </div>
        <div class="col-md-6 text-right">
        </div>
    </div>

    <div class="row">
        <div class="col-sm-12">
            <div class="box">
            @include('admin.partials.errors')
            @include('admin.partials.success')
            <div class="box-body">
            <table id="tags-table" class="table table-striped table-bordered">
                <thead>
                <tr>
                    <th data-sortable="false" class="hidden-sm"></th>
                    <th class="hidden-sm">权限规则</th>
                    <th class="hidden-sm">权限名称</th>
                    <th class="hidden-sm">权限概述</th>
                    <th class="hidden-md">权限创建日期</th>
                    <th class="hidden-md">权限修改日期</th>
                    <th data-sortable="false">操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
            </div>
        </div>
        </div>
    </div>
</div>
</div>
<div class="modal fade" id="modal-delete" tabIndex="-1">
<div class="modal-dialog modal-warning">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
                ×
            </button>
            <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body">
            <p class="lead">
                <i class="fa fa-question-circle fa-lg"></i>
                确认要删除这个软件吗?
            </p>
        </div>
        <div class="modal-footer">
            <form class="deleteForm" method="POST" action="/admin/list">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <input type="hidden" name="_method" value="DELETE">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="submit" class="btn btn-danger">
                    <i class="fa fa-times-circle"></i> 确认
                </button>
            </form>
        </div>




</div>
@stop

@section('js')
<script>
$(function () {
    var cid=$('#cid').attr('attr');
    var table = $("#tags-table").DataTable({
        language: {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        },
        order: [[5, "asc"]],
        serverSide: true,

        ajax: {
            url: '/admin/permission/index',
            type: 'POST',
            data: function (d) {
                d.cid = cid;
            },
            headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
            }
        },
        "columns": [
            {"data": "id"},
            {"data": "name"},
            {"data": "display_name"},
            {"data": "description"},
            {"data": "created_at"},
            {"data": "updated_at"},
            {"data": "action"}
        ],
        columnDefs: [
            {
                'targets': -1, "render": function (data, type, row) {
                if (cid == 0) {
                    return '<a style="margin:3px;"  href="/admin/permission/' + row['id'] + '" class="X-Small btn-xs text-success "><i class="fa fa-adn"></i>下级菜单</a><a style="margin:3px;" href="/admin/permission/' + row['id'] + '/edit" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a><a style="margin:3px;" href="#" attr="' + row['id'] + '" class="delBtn X-Small btn-xs text-danger"><i class="fa fa-times-circle"></i> 删除</a>';
                } else {
                    return '<a style="margin:3px;" href="/admin/permission/' + row['id'] + '/edit" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a><a style="margin:3px;" href="#" attr="' + row['id'] + '" class="delBtn X-Small btn-xs text-danger"><i class="fa fa-times-circle"></i> 删除</a>';
                }

            }
            }
        ]
    });

    table.on('preXhr.dt', function () {
        loadShow();
    });

    table.on('draw.dt', function () {
        loadFadeOut();
    });

    table.on('order.dt search.dt', function () {
        table.column(0, {search: 'applied', order: 'applied'}).nodes().each(function (cell, i) {
            cell.innerHTML = i + 1;
        });
    }).draw();

    $("table").delegate('.delBtn', 'click', function () {
        var id = $(this).attr('attr');
        $('.deleteForm').attr('action', '/admin/permission/' + id);
        $("#modal-delete").modal();
    });

});
</script>
@stop